<?php

namespace common\models\datas;

use Yii;

/**
 * This is the model class for table "{{%appointment}}".
 *
 * @property integer $id
 * @property integer $order_id
 * @property integer $order_sales_id
 * @property integer $category_id
 * @property integer $site_id
 * @property integer $appointment_time
 * @property integer $created_at
 */
class Appointment extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%appointment}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_id', 'order_sales_id', 'category_id', 'site_id', 'appointment_time', 'created_at'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', '自动编号'),
            'order_id' => Yii::t('common', '订单id'),
            'order_sales_id' => Yii::t('common', '订单课程id'),
            'category_id' => Yii::t('common', '课程分类id'),
            'site_id' => Yii::t('common', '分店id'),
            'appointment_time' => Yii::t('common', '预约时间'),
            'created_at' => Yii::t('common', '统计时间'),
        ];
    }

    public function extraFields()
    {
        return [
            'site_name' => function () {
                return !empty($this->site->name) ? $this->site->name : '';
            },
            'category_name' => function () {
                return $this->category->name;
            }
        ];
    }

    public function getSite()
    {

        return $this->hasOne(Site::className(), ['id' => 'site_id']);
    }

    public function getCategory()
    {

        return $this->hasOne(Category::className(), ['id' => 'category_id']);
    }

}
